/// @tags: SegTree Stack Construct
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

namespace BlueQuantum {

typedef long long ll;

#define MN 500000
#define N 1048576

int n, m, a[MN + 5], b[MN + 5], al, ar, bl, br;
int A[MN + 5], B[MN + 5], u[MN * 2 + 5], v[MN + 5];
ll x[MN + 5], y[MN + 5], ans;

struct Node {
  ll x, tag;
} tr[N + 5];

inline void pushup(int x) { tr[x].x = max(tr[x << 1].x, tr[x << 1 | 1].x); }

inline void mark(int k, ll x) { tr[k].x += x, tr[k].tag += x; }

inline void pushdown(int k) {
  if (tr[k].tag) mark(k << 1, tr[k].tag), mark(k << 1 | 1, tr[k].tag), tr[k].tag = 0;
}

void build(int k, int l, int r, ll x, ll* y) {
  if (l == r) {
    tr[k].x = x - y[l ? v[l - 1] : 0];
    return;
  }
  int mid = (l + r) >> 1;
  build(k << 1, l, mid, x, y);
  build(k << 1 | 1, mid + 1, r, x, y);
  pushup(k);
  tr[k].tag = 0;
}

void add(int k, int l, int r, int ql, int qr, ll x) {
  if (l == ql && r == qr) {
    tr[k].x += x;
    tr[k].tag += x;
    return;
  }
  int mid = (l + r) >> 1;
  pushdown(k);
  if (qr <= mid) add(k << 1, l, mid, ql, qr, x);
  else if (ql > mid)
    add(k << 1 | 1, mid + 1, r, ql, qr, x);
  else
    add(k << 1, l, mid, ql, mid, x), add(k << 1 | 1, mid + 1, r, mid + 1, qr, x);
  pushup(k);
}

int get(int k, int l, int r) {
  if (l == r) return l;
  int mid = (l + r) >> 1;
  pushdown(k);
  return tr[k << 1].x == tr[k].x ? get(k << 1, l, mid) : get(k << 1 | 1, mid + 1, r);
}

void solve(int n, int m, int* a, int* b, ll* const x, ll* const y, bool dir) {
  int j, p, mid = lower_bound(x + 1, x + n + 1, (x[n] + 1) >> 1) - x, cnt = 0;
  for (int i = 1; i <= n; ++i)
    if (a[i]) v[cnt++] = a[i];
  sort(v, v + cnt);
  build(1, 0, cnt, x[n], y);
  for (int i = 0, An = 0, Bn = 0; i <= cnt; ++i) {
    if (i) {
      if (b[v[i - 1]] < mid) {
        add(1, 0, cnt, A[An] + 1, i - 1, -x[b[v[i - 1]]]);
        while (An && b[v[i - 1]] > b[v[A[An]]])
          add(1, 0, cnt, A[An - 1] + 1, A[An], x[b[v[A[An]]]] - x[b[v[i - 1]]]), --An;
        A[++An] = i - 1;
      } else {
        add(1, 0, cnt, B[Bn] + 1, i - 1, x[b[v[i - 1]] - 1] - x[n]);
        while (Bn && b[v[i - 1]] < b[v[B[Bn]]])
          add(1, 0, cnt, B[Bn - 1] + 1, B[Bn], x[b[v[i - 1]] - 1] - x[b[v[B[Bn]]] - 1]),
              --Bn;
        B[++Bn] = i - 1;
      }
    }
    if (y[i < cnt ? v[i] - 1 : m] + tr[1].x > ans) {
      ans = y[i < cnt ? v[i] - 1 : m] + tr[1].x;
      j = get(1, 0, cnt);
      p = lower_bound(A + 1, A + An + 1, j) - A;
      (dir ? bl : al) = p <= An ? b[v[A[p]]] + 1 : 1;
      p = lower_bound(B + 1, B + Bn + 1, j) - B;
      (dir ? br : ar) = p <= Bn ? b[v[B[p]]] - 1 : n;
      (dir ? al : bl) = j ? v[j - 1] + 1 : 1;
      (dir ? ar : br) = i < cnt ? v[i] - 1 : m;
    }
  }
}

inline int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) cin >> x[i], x[i] += x[i - 1];
  for (int i = 1; i <= m; ++i) cin >> b[i];
  for (int i = 1; i <= m; ++i) cin >> y[i], y[i] += y[i - 1];
  ans = x[n], al = 1, ar = n, bl = br = 0;
  if (y[m] > ans) ans = y[m], al = ar = 0, bl = 1, br = m;
  for (int i = 1; i <= m; ++i) u[b[i]] = i, b[i] = 0;
  for (int i = 1; i <= n; ++i) a[i] = u[a[i]], b[a[i]] = i;
  A[0] = B[0] = -1;
  solve(n, m, a, b, x, y, 0);
  solve(m, n, b, a, y, x, 1);
  cout << ans;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("seq.in", "r", stdin);
  freopen("seq.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
